<html>
<head>

<title>Groovy Goodness: Get Hints About Missing Methods or Properties</title>

<script language="javascript" src="scripts/shCore.js"></script> 
<script language="javascript" src="scripts/shLegacy.js"></script> 
<script language="javascript" src="scripts/shBrushJava.js"></script> 
<script language="javascript" src="scripts/shBrushXml.js"></script> 
<script language="javascript" src="scripts/shBrushJScript.js"></script> 
<script language="javascript" src="scripts/shBrushGroovy.js"></script> 
<script language="javascript" src="scripts/shBrushPlain.js"></script> 
<script language="javascript" src="scripts/shBrushBash.js"></script> 
 
<link href="styles/reset.css" rel="stylesheet" type="text/css" />
<link href="styles/shCore.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="styles/shThemeRDark.css"/>
<link href="styles/blog.css" rel="stylesheet" type="text/css" />

</head>
<body>

<a href="index.html">Back to index</a>

<h3 class="post-title">Groovy Goodness: Get Hints About Missing Methods or Properties</h3>

<div class="post">
<p>Groovy helps us if for example we make a small mistake in our code. We don't only get an error message, but also a hint about a possible solution. This works also for classes we create ourselves.</p>
<p>In the following example we use <code>toUppercase()</code> instead of <code>toUpperCase()</code>. Notice the suggestion we get from Groovy:</p>
<pre class="brush:plain">
$ groovy -e "println 'mrhaki'.toUppercase()"
Caught: groovy.lang.MissingMethodException: No signature of method: java.lang.String.toUppercase() is applicable for argument types: () values: []
Possible solutions: toUpperCase(), toUpperCase(java.util.Locale), toLowerCase(), toLowerCase(java.util.Locale)
 at script_from_command_line.run(script_from_command_line:1)
</pre>
<p>Suppose we define the following script:</p>
<pre class="brush:groovy">
class User {
    String name
    String giveName() { name }
}

def u = new User(name: 'mrhaki')
println u.givenName()
</pre>
<p>When we run this script we get the following output:</p>
<pre class="brush:plain">
$ groovy UserScript.groovy 
Caught: groovy.lang.MissingMethodException: No signature of method: User.givenName() is applicable for argument types: () values: []
Possible solutions: giveName(), getName(), setName(java.lang.String)
 at UserScript.run(UserScript.groovy:7)
</pre
</div>

<script language="javascript"> 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'scripts/clipboard.swf';
SyntaxHighlighter.defaults['first-line'] = 0;
SyntaxHighlighter.defaults['auto-links'] = false;
SyntaxHighlighter.all();
dp.SyntaxHighlighter.HighlightAll('code');
</script>

</body>
</html>